package com.hry.sunflower.config;

import com.hry.sunflower.common.Constant;
import com.hry.sunflower.job.SyncGpsData;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfiguration {

    @Bean
    public JobDetail GpsDataSyncJobJObDetail() {
        return JobBuilder.newJob(SyncGpsData.class).withDescription("GpsSyncData").storeDurably().build();
    }

    @Bean
    public Trigger GpsDataSyncTrigger() {
        // 指定每隔一定时间重复执行
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(Constant.TIME).repeatForever();
        return TriggerBuilder.newTrigger().forJob(GpsDataSyncJobJObDetail()).withIdentity("GpsDataSyncTrigger").withSchedule(scheduleBuilder).build();
    }
}
